package com.weasel.http;

import java.io.IOException;

import com.weasel.http.builder.*;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;

import org.apache.http.util.EntityUtils;

/**
 * @author Dylan
 * @time 2015年9月24日
 */
public final class HttpClientSecretary {

	public static HttpGetMethodBuilder get(){
		return new HttpGetMethodBuilder();
	}
	
	public static HttpPostMethodBuilder post(){
		return new HttpPostMethodBuilder();
	}
	
	public static HttpDeleteMethodBuilder delete(){
		
		return new HttpDeleteMethodBuilder();
	}
	
	public static HttpPutMethodBuilder put(){
		
		return new HttpPutMethodBuilder();
	}
	
	public static HttpPatchMethodBuilder patch(){
	
		return new HttpPatchMethodBuilder();
	}
	
	public static HttpOptionsMethodBuilder options(){
		
		return new HttpOptionsMethodBuilder();
	}
	
	public static HttpTraceMethodBuilder trace(){
		
		return new HttpTraceMethodBuilder();
	}

	public static HttpHeadMethodBuilder head(){

		return new HttpHeadMethodBuilder();
	}

	/**
	 * @param response
	 */
	public static void release(CloseableHttpResponse response){
		
		if(null == response){
			return;
		}
		final HttpEntity entity = response.getEntity();
        try {
			EntityUtils.consume(entity);
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			try {
				response.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	
	
	private HttpClientSecretary(){}
}
